// TOWN SCRIPT
//    Town 9: Spooky Cave

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,choice;
short lead_char;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered

 i = 0;
 while (i < 5) {
  if (char_ok(i)) {
   lead_char = i;
   i = 5;
  }
  else
   i = i + 1;
 }

 if (get_sdf(3,22) > 0)
  erase_char(27);

 set_crime_tolerance(1);

force_instant_terrain_redraw();
if (get_sdf(3,16) == 0) {
 set_flag(3,16,1);
 message_dialog("You stumble into a small, damp cavern. The passage ahead quickly branches off in two directions. In the distance you hear strange drops and hisses.","There is something about this cavern that makes you feel very uncomfortable. You cannot pin it down, but the atmosphere is quite spooky.");
}

if (get_sdf(4,10) < 3)
 play_sound(150);
else
 play_sound(151);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;

break;


beginstate 10;

if (get_sdf(3,17) == 0) {
 set_flag(3,17,1);
 message_dialog("Just ahead you see the remains of a quite recent campsite. Two Nephilim have been heavily clawed to death in their sleep. The smell of decay is ripe and cannot be over a few days old.","A trail of blood leads away from the site and toward you. Needless to say, this does not ease your queasiness about this cavern.");
}

break;


beginstate 11;

if (get_sdf(3,18) == 0) {
 set_flag(3,18,1);
 message_dialog("A chilly breeze comes from this passage. You swear that in the wind you hear a whisper saying _Stay back..._","");
}

break;


beginstate 12;

if (get_sdf(3,19) == 0) {
 set_flag(3,19,1);
 activate_hidden_group(1);
 put_effect_on_char(14,0,5,0);
 put_effect_on_char(18,0,5,0);
 put_effect_on_char(19,0,5,0);
 force_instant_terrain_redraw();
 run_animation_sound(75);
 pause(5);
 message_dialog("Three shades materialize out of the cool air. These creatures are likely responsible for haunting this cavern. They clearly don't want you to leave either.","");
}

break;


beginstate 13;

if (get_sdf(3,20) == 0) {
 set_flag(3,20,1);
 message_dialog("You manage to find a concealed passage in the rocks. You look beyond and you see some ruins of a floor pattern you've never seen before. Unfortunately, the back wall has caved in, burying most of it.","A spirit floats silently above a rune making no move. Beside it is a shimmering crystal box, at least you think it's a box. The figure stares at you blankly and does nothing else.");
}

break;


beginstate 14;

if (get_sdf(3,21) == 0) {
 set_flag(3,21,1);
 message_dialog("You touch the crystal box and the cover automatically slides open. The rest of the box grows dark. You peer inside and see a black daggar. You shine a light closer and it seems to absorb all light.","You have found a very strange artifact in an unexpected and remote place. You wonder who put this here.");
}

break;